package com.greatwqs.wmall.order.client.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 *
 * 对应表：order.order_type （订单类型：1 普通，2 秒杀）
 * @author wang-qingsong
 */
@Getter
@AllArgsConstructor
public enum OrderType {

    NORMAL(1, "普通订单"),
    FLASH_SALE(2, "秒杀订单");

    private final int value;
    private final String name;

    public static OrderType of(int value) {
       return Arrays.stream(OrderType.values())
               .filter(orderType -> orderType.getValue() == value)
               .findFirst()
               .orElseThrow(() -> new IllegalArgumentException("OrderType invalid value: " + value ));
    }
}
